package com.eshopkeeper.core.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class SensitiveWordInit
{

    public HashMap sensitiveWordMap;

    public Map addSensitiveWordToHashMap(List<String> keyWordList)
    {

        sensitiveWordMap = new HashMap(keyWordList.size());
        String key = null;
        Map nowMap = null;
        Map<String, Object> newWorMap = null;
        Iterator<String> iterator = keyWordList.iterator();
        while (iterator.hasNext())
        {
            key = iterator.next();
            nowMap = sensitiveWordMap;
            for (int i = 0; i < key.length(); i++)
            {
                char keyChar = key.charAt(i);
                Object wordMap = nowMap.get(keyChar);
                if (wordMap != null)
                {
                    nowMap = (Map) wordMap;
                }
                else
                {
                    newWorMap = new HashMap<String, Object>();
                    newWorMap.put("isEnd", false);
                    nowMap.put(keyChar, newWorMap);
                    nowMap = newWorMap;
                }
                if (i == key.length() - 1)
                {
                    nowMap.put("isEnd", true);
                }
            }
        }
        return sensitiveWordMap;
    }
}